package pub.tbc.toolkit;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

public class Unsafes {
    /**
     * 通过反射获取{@link Unsafe}对象
     * @throws IllegalAccessException
     */
    public static Unsafe getUnsafe() throws IllegalAccessException {
        Field unsafeField = Unsafe.class.getDeclaredFields()[0];
        unsafeField.setAccessible(true);
        return (Unsafe) unsafeField.get(null);
    }

    public static void main(String[] args) throws IllegalAccessException {
        for (; ; ) getUnsafe().allocateMemory(1024 * 1024);
    }
}
